package com.jinmei.web.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.jinmei.model.ToDoList;
import com.jinmei.service.ToDoListService;
import com.jinmei.web.TaskDTO;

public class TaskAction extends BaseAction{

	private static final long serialVersionUID = 1L;

	private ToDoListService toDoListService;
	
	private List<TaskDTO> taskResults;
	
	public String getTasksByEmployee() throws Exception{
		String employeeId = request.getParameter("FId");
		List<ToDoList> tasks = toDoListService.getTasksByEmployeeId(employeeId);
		taskResults = new ArrayList<TaskDTO>();
		for(ToDoList task : tasks){
			TaskDTO dto = new TaskDTO();
			dto.setContents(task.getContents());
			dto.setfId(task.getEmployee().getfId().toString());
			//TODO: format the time
			dto.setEndDateTime(task.getEndDateTime().toString());
			dto.setId(task.getId().toString());
			dto.setIsCompleted(task.getIsCompleted().toString());
			dto.setStartDateTime(task.getStartDateTime().toString());
			dto.setSubject(task.getSubject());
			taskResults.add(dto);
		}
		return SUCCESS;
	}
	
	public ToDoListService getToDoListService() {
		return toDoListService;
	}

	public void setToDoListService(ToDoListService toDoListService) {
		this.toDoListService = toDoListService;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public List<TaskDTO> getTaskResults() {
		return taskResults;
	}

	public void setTaskResults(List<TaskDTO> taskResults) {
		this.taskResults = taskResults;
	}

}
